<%@  language="VBScript" %>
<%  Option Explicit %>
<!--#include virtual="adovbs.inc"-->

<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns="http://www.w3.org/TR/REC-html40">
<head>
	<title>Photos Albums</title>
	<link rel="stylesheet" type="text/css" href="MainCSS.css" />
	<link href="demo.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript">
		function getPhotos(albumID, userName, div) {
			populatePhotos(albumID, userName, div);
		}
	</script>
	<script type="text/javascript" src="MainJS.js"></script>

	<%
	Dim objConn, objRSCustomers, objRSAlbums, objRSPhotos
	Dim strUserName, strSQL, strResults, strDiv
	Dim iCustID
	Dim albumID, icol
	strDiv = "photoDiv"
	Response.Expires = -1500    
	iCustID = Request.QueryString("custID")
	Set objConn = Server.CreateObject("ADODB.Connection")
	objConn.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;UID=sa;PWD=~nguyen123;Initial Catalog=DEVELOPER;Server=NANKA-PC" '"Provider=SQLOLEDB.1;Persist Security Info=False;UID=sa;PWD=MKkb1980;Initial Catalog=HomeTeamOnline;Server=."    
	objConn.Open
	
	strSQL = "SELECT username FROM customers WHERE customerID = " & iCustID
	Set objRSCustomers = Server.CreateObject("ADODB.Recordset")
	objRSCustomers.Open strSQL, objConn
	Do While Not objRSCustomers.EOF
		strUserName = objRSCustomers("username")
		objRSCustomers.MoveNext
	Loop	
	objRSCustomers.Close
	set objRSCustomers = Nothing

	strSQL = "SELECT * FROM photos WHERE RTRIM(username) = '" & Trim(strUserName) & "'"
	set objRSPhotos = Server.CreateObject("ADODB.Recordset")
	objRSPhotos.Open strSQL, objConn
	
	strSQL = "SELECT * FROM photoAlbums WHERE RTRIM(username) = '" & Trim(strUserName) & "'"
	Set objRSAlbums = Server.CreateObject("ADODB.Recordset")
	objRSAlbums.Open strSQL, objConn
	%>

</head>
<body onload="setDivLocation('photoAlbumDiv','photoDiv','uploadDiv','displayTD');">
	<br />
	<table id="displayTD" align="center" width="700px">
		<tr>
			<td id="tdAlbums" width="10%" align="center" style="background: gray; font-family: arial;
				font-weight: bold; font-size: 12px; border: 1px solid #FFFFFF" onmouseover="this.style.background='purple'"
				onmouseout="this.style.background='gray'">
				<a style="text-decoration: none; color: white" onclick="DisplayDiv('photoDiv','uploadDiv','photoAlbumDiv');">
					Albums</a>
			</td>
			<td id="tdPhotos" width="10%" align="center" style="background: gray; font-family: arial;
				font-weight: bold; font-size: 12px; border: 1px solid #FFFFFF" onmouseover="this.style.background='purple'"
				onmouseout="this.style.background='gray'">
				<a style="text-decoration: none; color: white" onclick="DisplayDiv('photoAlbumDiv','uploadDiv','photoDiv');">
					Photos</a>
			</td>
			<td width="70%">
			</td>
			<td id="tdUpload" width="10%" align="center" style="background: gray; font-family: arial;
				font-weight: bold; font-size: 12px; border: 1px solid #FFFFFF" onmouseover="this.style.background='purple'"
				onmouseout="this.style.background='gray'">
				<a style="text-decoration: none; color: white" onclick="DisplayDiv('photoAlbumDiv','photoDiv','uploadDiv');">
					Upload</a>
			</td>
		</tr>
		<tr>
			<td colspan="4" style="background: gray; color: white">
				<div id="photoAlbumDiv">
					<table width="100%" style="border: 1px solid #FFFFFF">
						<tr>
							<%
						If Not objRSAlbums.EOF then			    	 
							icol = 0	    
							Do While Not objRSAlbums.EOF
								icol = icol + 1					        	
								albumID = objRSAlbums("albumID")			
								'sql not accepted filter		            
								'objRSPhotos.Filter = "albumID = '" & albumID & "' AND priority = 1"
								Do While Not objRSPhotos.EOF
									If (objRSPhotos("albumID") = albumID) AND (objRSPhotos("priority") = 1) then
										Exit Do
									End If
									objRSPhotos.MoveNext
								Loop
								If icol = 1 then
									
									'Response.Write "<script type='text/javascript'>populatePhotos(" & albumID & "," & strUserName & ",'photoDiv');</script>"
									'onLoad = getPhotos(2,"John","photoDiv")
									Response.Write "<script type='text/javascript'>getPhotos(2,'John','photoDiv');</script>"
									Response.Write "<td style='color:white; background:purple; font-family: arial; font-size:12px; font-weight:bold; width:25%'"
								Else
									Response.Write "<td style='color:white; font-family: arial; font-size:12px; font-weight:bold; width:25%'"
								End If
								Response.Write " id='TD" & icol &"'"
								Response.Write " onMouseOver=""this.style.background='purple'"" onMouseOut=""this.style.background='gray'"">"
								Response.Write "<p align='center'>"
								Response.Write "<img border='0' src='photos/" & objRSAlbums("username") & "/" & objRSPhotos("fileName") & "' height='127'"
								Response.Write "onClick=""displayPhotos(" & albumID & ",'" & strUserName & "','photoDiv');"""
								Response.Write "><BR><BR>"
								Response.Write Server.HTMLEncode(objRSAlbums("albumName")) & "<BR>"
								Response.Write "</td>"
								If ((icol / 4) = 0) then
									Response.Write "</tr><tr>"
								End If	
								objRSAlbums.MoveNext
							Loop
							If ((icol / 4) = 0) then
								Response.Write "<tr>"
							End If
							Response.Write "<td align='center' style='border: 2px dotted #FFFFFF; color:white; font-family: arial; font-size:12px; font-weight:bold; height:150px'"
							Response.Write " onMouseOver=""this.style.background='purple'"" onMouseOut=""this.style.background='gray'"">"
							Response.Write "<input type='button' value='Add New Album'/>"
							Response.Write "</td></tr></table>"
						Else
							Response.Write "Not found!"
						End If
						objRSAlbums.Close
						set objRSAlbums = Nothing
						objRSPhotos.Close
						set objRSPhotos = Nothing
						objConn.Close
						set objConn = Nothing
							%>
				</div>
				<div id="photoDiv">
				</div>
				<div id="uploadDiv">
				</div>
			</td>
		</tr>
	</table>
</body>
</html>
